home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1984-03-05 | 3.1 KB | 47 lines |
- 1 REM IBM PC ------- NUM-WORD ---------
- 2 REM VERSION$= "V1.2" '8/14/82
- 3 REM Author: Herb Shear, 1590 Vineyard Dr. Los Altos, CA 94022
- 4 REM Adapted from NUMWORD [Creative Computing, 6/82 p176] by Michael Sorens
- 5 '
- 6 'Author commentary: Returning P$ rather than printing while crunching allows
- 7 'the calling program to vary print fonts, add "protection" and otherwise
- 8 'play games with the literal and the available print space.
- 9 'The limit for SNG precision is about $130,000.00. Stating the purchase
- 10 'price on a deposit receipt for a simple home sale requires larger values.
- 11 'Handling the error condition, [P$=""] is up to the calling program.
- 12 'Other enhancements are the "-" where required by english syntax, leading
- 13 'zero/NO/100, only and setting it up about as close to a callable procedure
- 14 'as one can achieve in BASIC. All of which is just polish on Sorens's gem.
- 15 ' The literal syntax has been approved by an experienced bank officer.
- 16 ' NONE and EXACTLY are not proper syntax.
- 100 CLS
- 110 INPUT "ENTER AMOUNT"; SUM#
- 120 GOSUB 5000 NUM-LITERAL
- 130 IF LEN(P$) THEN PRINT P$: PRINT ELSE PRINT "Exceeds accuracy limits, use a smaller number!"
- 140 GOTO 110
- 150 '-------all the above is just for demo ---ps: list w/ LISTER for readabilityedit 80
- 160 '
- 5000 'Procedure NUM-LITERAL(SUM#,P$); value SUM#; ------------
- 5010 ' returns literal expression of SUM# in P$
- 5020 ' LSUM#, TEMP1#, TEMP2#, TEMP3#, TEMP4# TEMP5#, CENTS%, I%, NUMWORD$
- 5030 P$ = "": IF SUM# > 1.98E+14 THEN RETURN ELSE LSUM#=SUM#
- 5040 IF LEN(NUMWORD$(2)) THEN ELSE GOSUB 5200
- 5050 CENTS%=INT((LSUM#-INT(LSUM#))*100+0.5) :LSUM#=INT(LSUM#)
- 5060 IF LSUM# THEN GOSUB 5100: P$ = P$ + "AND " ELSE P$ = "ONLY "
- 5070 IF CENTS% THEN P$ = P$ +RIGHT$("0"+MID$(STR$(CENTS%),2,2),2) ELSE P$=P$+"NO"
- 5080 P$ = P$ + "/100 DOLLARS"
- 5090 RETURN
- 5100 '-------- recursive subroutine to express numbers as words-----
- 5110 IF LSUM# > 1E+12 THEN TEMP5# = LSUM#-INT(LSUM#/1E+12)*1E+12: LSUM# = INT(LSUM#/1E+12): GOSUB 5100: P$ =P$ + "TRILLION ": LSUM# = TEMP5#
- 5120 IF LSUM# > 1E+09 THEN TEMP4# = LSUM#-INT(LSUM#/1E+09)*1E+09: LSUM# = INT(LSUM#/1E+09) :GOSUB 5100: P$ = P$ + "BILLION ": LSUM# = TEMP4#
- 5130 IF LSUM# > 999999 THEN TEMP3# = LSUM#-INT(LSUM#/1E+06)*1E+06: LSUM# = INT(LSUM#/1E+06): GOSUB 5100: P$ = P$ + "MILLION ": LSUM# = TEMP3#
- 5140 IF LSUM# > 999 THEN TEMP2# = LSUM#-INT(LSUM#/1000)*1000: LSUM# = INT(LSUM#/1000): GOSUB 5100: P$ = P$ + "THOUSAND ": LSUM# = TEMP2#
- 5150 IF LSUM# > 99 THEN TEMP1# = LSUM#: LSUM# = INT(LSUM#/100) :GOSUB 5100: P$ = P$ + "HUNDRED ": LSUM# = TEMP1#-LSUM#*100
- 5160 IF LSUM# > 19 THEN P$ = P$ + NUMWORD$(INT(LSUM#/10)): LSUM# = LSUM#-10*INT(LSUM#/10): IF LSUM# THEN P$ =P$ + "-": ELSE P$=P$ +" "
- 5170 IF LSUM# THEN P$ = P$ + NUMWORD$(LSUM#+9)+" "
- 5180 RETURN
- 5190 '--------- initilization --------------------------------------------
- 5200 ERASE NUMWORD$:DIM NUMWORD$(28): RESTORE 5210: FOR I%=2 TO 28: READ NUMWORD$(I%): NEXT: RETURN
- 5210 DATA TWENTY,THIRTY,FORTY,FIFTY,SIXTY,SEVENTY,EIGHTY,NINETY
- 5220 DATA ONE,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE,TEN,ELEVEN,TWELVE, THIRTEEN,FOURTEEN,FIFTEEN,SIXTEEN,SEVENTEEN,EIGHTEEN,NINETEEN
-